package com.nhncorp.lucy.template.action;

import java.net.URLDecoder;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.nhncorp.lucy.common.container.SpringBeanFactory;
import com.nhncorp.lucy.common.util.DataMap;
import com.nhncorp.lucy.template.bo.HelloBO;
import com.nhncorp.lucy.web.actions.BaseAction;
import com.nhncorp.lucy.web.context.ServiceContext;

@SuppressWarnings("serial")
public class HelloAction extends BaseAction {
	public String getMessage() {
		return "Hello World!!";
	}
	
	public String getGpdm() {
		HelloBO helloBO = (HelloBO)SpringBeanFactory.getBean("helloBo");
		Map map = helloBO.selectGpdm();
		ServiceContext.setAttribute("map", map);
		return "result";
	}
	
	public String updateGpdm() {
		HelloBO helloBO = (HelloBO)SpringBeanFactory.getBean("helloBo");
		String v_zqdm = ServiceContext.getParameter("v_zqdm");
		helloBO.updateGpdm(v_zqdm);
		return "success";
	}
	
	@Override
	public String execute() throws Exception {
		String v_tpage = ServiceContext.getParameter("v_tpage");
		String v_cpage = ServiceContext.getParameter("v_cpage");
		String v_zqjc = ServiceContext.getParameter("v_zqjc");
		v_zqjc = URLDecoder.decode(v_zqjc, "UTF-8");
		String v_zqdm = ServiceContext.getParameter("v_zqdm");
		String v_zsp = ServiceContext.getParameter("v_zsp");
		String v_cjmx = ServiceContext.getParameter("v_cjmx");
		String upd_date = ServiceContext.getParameter("upd_date");
		String [] v_cjmxData = null;
		
		if (v_cjmx.indexOf("],[") > 0) {
			HelloBO helloBO = (HelloBO)SpringBeanFactory.getBean("helloBo");
			v_cjmx = v_cjmx.replace("\"", "");
			v_cjmx = v_cjmx.replace("],[", "&");
			v_cjmxData = StringUtils.split(v_cjmx, "&");
			for (int i = 0; i < v_cjmxData.length; i++) {
				String string = v_cjmxData[i];
				String[] data = string.split(",");
				Map map = new DataMap();
				map.put("cj_time", data[0]);
				map.put("cj_price", data[1]);
				map.put("cj_biandong", data[2]);
				map.put("cj_liang", data[3]);
				map.put("cj_jinE", data[4]);
				map.put("cj_xingZi", data[5]);
				map.put("gp_dm", v_zqdm);
				map.put("gp_jc", v_zqjc);
				map.put("upd_date", upd_date);
				helloBO.insertGP(map);
			}
		}
		System.out.println("v_zqjc=== " + v_zqjc);
		return SUCCESS;
	}
}
